from world_object import WorldObject
import pygame
import constants
import os
import data

class Text(WorldObject):
    def __init__(self, message="!", x=2, y=2, ttl=None, size=24, color=(190,190,120), speed=0, angle=0):
        """Specify ttl in seconds, if None the text will last forever"""

        WorldObject.__init__(self, x, y, speed=speed, angle=angle)
        self._ttl = ttl
        if self._ttl != None: self._ttl *= constants.FRAME_RATE
        self._font = pygame.font.Font(os.path.join(data.data_dir, 'FreeSansBold.ttf'), int(size))
        self._color = color
        self.update_surface(message)
        self.z_index = 0

    def update_surface(self, message):
        self._message = message
        self.image = self._font.render(str(self._message), True, self._color)

    def tick_update(self):
        WorldObject.tick_update(self)
        if self._ttl != None:
            self._ttl -= 1
            if self._ttl < 0: self.die()

    def should_scroll_down(self):
        return False

    def __str__(self):
        return "text %s" % WorldObject.__str__(self)
